define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'diy/push/index' + location.search,
                    add_url: 'diy/push/add',
                    edit_url: 'diy/push/edit',
                    del_url: 'diy/push/del',
                    multi_url: 'diy/push/multi',
                    import_url: 'diy/push/import',
                    table: 'diy_push',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id'), addClass: "selectpage", extend: "data-source='user/user/index' data-field='username'"},
                        {field: 'user.username', title: __('用户名'),operate:false},
                        {field: 'community', title: __('Community'),visible:false,switchable:false,searchList:Config.communityList},
                        {field: 'community_text', title: __('Community'),operate:false},
                        {field: 'min_rent', title: __('Min_rent'), operate:'BETWEEN'},
                        {field: 'max_rent', title: __('Max_rent'), operate:'BETWEEN'},
                        {field: 'min_floor', title: __('Min_floor')},
                        {field: 'max_floor', title: __('Max_floor')},
                        {field: 'house_type', title: __('House_type'),visible:false,switchable:false, operate: false},
                        {field: 'house_type_text', title: __('House_type'), operate: false},
                        {field: 'payment_type', title: __('Payment_type'),visible:false,switchable:false, operate: false},
                        {field: 'payment_type_text', title: __('Payment_type'), operate: false},
                        {field: 'status', title: __('状态'),searchList:Config.statusList,formatter: Table.api.formatter.status},
                        {field: 'tags_text', title: __('Tags'), operate: false, formatter: Table.api.formatter.flag},
                        {field: 'house.name', title: __('推送房源名称')},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
